// 提交链接：https://leetcode.cn/problems/relocate-marbles/description/
// lc2766. 重新放置石块
// 完成日期：2024/11/3
// c++ 哈希表 数组

class Solution {
public:
    vector<int> relocateMarbles(vector<int>& nums, vector<int>& moveFrom, vector<int>& moveTo) {
        map<int,int> mp;
        int n = nums.size();
        int m = moveFrom.size();
        for(int i=0; i<n; i++)
            mp[nums[i]]++;
        for(int i=0; i<m; i++)
        {
            int sum = mp[moveFrom[i]];
            mp.erase(moveFrom[i]);
            mp[moveTo[i]] += sum;
        }
        vector<int> ans;
        for(auto it:mp)
            ans.push_back(it.first);
        return ans;
        
    }
};